package com.example.myapplication.adapter

import android.app.Activity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.ImageView
import android.widget.TextView
import com.example.myapplication.R
import com.example.myapplication.model.Student

class StudentAdapter(activity: Activity,val resourceId:Int,data:List<Student>):
ArrayAdapter<Student>(activity,resourceId,data){
    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        val view=LayoutInflater.from(context).inflate(resourceId,parent,false)
        val stuno:TextView=view.findViewById(R.id.stuno)
        val stuname:TextView=view.findViewById(R.id.stuname)
        val classes:TextView=view.findViewById(R.id.classes)
        val gender:TextView=view.findViewById(R.id.gender)
        val department:TextView=view.findViewById(R.id.department)
        val tel:TextView=view.findViewById(R.id.tel)
        val photopath:ImageView=view.findViewById(R.id.photopath)
        val student=getItem(position)
        if(student!=null){
            stuno.text=student.stuNo
            stuname.text=student.stuName
            classes.text=student.classes
            gender.text=student.gender
            department.text=student.department
            tel.text=student.tel
            if(student.gender=="男")
            photopath.setImageResource(R.drawable.boy)
        if(student.gender=="女"){
            photopath.setImageResource(R.drawable.girl)
        } }
        return view
    }
}